package com.xwq.administrator.lljk;

import android.content.Context;
import android.database.sqlite.SQLiteDatabase;
import android.database.sqlite.SQLiteOpenHelper;

/**
 * Created by Administrator on 2016/12/10.
 */
public class DbHelper extends SQLiteOpenHelper{
    public DbHelper(Context context) {
        super(context, DbConstants.DB_NAME, null, DbConstants.DB_VERSION);
    }

    @Override
    public void onCreate(SQLiteDatabase sqLiteDatabase) {
        sqLiteDatabase.beginTransaction();
        try {
            sqLiteDatabase.execSQL(DbConstants.CREATE_TRAFFIC_TABLE_SQL.toString());
            sqLiteDatabase.setTransactionSuccessful();
        }finally {
            sqLiteDatabase.endTransaction();
        }
    }

    @Override
    public void onUpgrade(SQLiteDatabase sqLiteDatabase, int i, int i1) {
        sqLiteDatabase.beginTransaction();
        try{
            sqLiteDatabase.execSQL(DbConstants.DELETE_TRAFFIC_TABLE_SQL.toString());
            sqLiteDatabase.execSQL(DbConstants.CREATE_TRAFFIC_TABLE_SQL.toString());
            sqLiteDatabase.setTransactionSuccessful();
        }finally {
            sqLiteDatabase.endTransaction();
        }
    }
}
